package com.beyond.trace.domain.vo.Knowledge;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.beyond.trace.domain.knowledgebase.CropKnowledge;
import com.beyond.trace.domain.knowledgebase.DiseasePestKnowledge;
import com.beyond.trace.domain.knowledgebase.KnowledgeBase;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName: KnowledgeBaseBo
 * @author: z越
 * @date: 2024/2/20  14:13
 * @description
 */
@Data
@ApiModel("知识库")
@NoArgsConstructor
public class KnowledgeBaseBo {
    @ApiModelProperty("主键id")
    private Long id;
    @ApiModelProperty("名称")
    private String name;
    @ApiModelProperty("简介")
    private String profile;
    @ApiModelProperty("形态特征")
    private String formFeature;
    @ApiModelProperty("图片")
    private String pictures;
    @ApiModelProperty("类型（pest:虫害，crop：植物，disease：病害）")
    private String type;
    @ApiModelProperty("植物知识库扩展数据")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private CropKnowledge cropExtend;
    @ApiModelProperty("病害、虫害知识库扩展数据")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private DiseasePestKnowledge diseasePest;

    public KnowledgeBaseBo(KnowledgeBase po){
        this.id = po.getId();
        this.name = po.getName();
        this.profile = po.getProfile();
        if (StringUtils.isNotEmpty(po.getPictures())){
           String[] split = po.getPictures().split(",");
            this.pictures = String.join(",", split);
        }
        this.formFeature = po.getFormFeature();
        this.type = po.getType();
        if ("pest".equals(po.getType()) || "disease".equals(po.getType())){
            this.diseasePest = (DiseasePestKnowledge)po.getExtend();
        }
        if ("crop".equals(po.getType())){
            this.cropExtend = (CropKnowledge)po.getExtend();
        }
    }
}
